package org.toools.gwt.wmc.jpa;

import java.io.Serializable;
import java.util.Collection;
import java.util.Vector;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author stefan asseg
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Container.getAll", query = "SELECT a FROM Container a"),
    @NamedQuery(name = "Container.getById", query = "SELECT a FROM Container a WHERE a.id = :id"),
    @NamedQuery(name = "Container.getByName", query = "SELECT a FROM Container a WHERE a.name = :name")
})
public class Container implements Serializable, com.google.gwt.user.client.rpc.IsSerializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
    private String name;
    private Integer container_size;
    @ManyToMany(fetch=FetchType.EAGER)
    private Collection<CompanyPart> companyParts = new Vector<CompanyPart>();
    @ManyToMany( fetch=FetchType.EAGER)
    private Collection<Waste> waste = new Vector<Waste>();
    @ManyToOne
    private Disposer disposer;

    public Container() {
    }

    public Container(String name) {
        this.name = name;
    }

    public Container(String name, Disposer disposer, Integer size) {
        this.name = name;
        this.disposer = disposer;
        this.container_size = size;
    }

    public Container(String name, Collection<CompanyPart> companyParts, Integer size) {
        this.name = name;
        this.companyParts = companyParts;
        this.container_size = size;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getSize() {
        return container_size;
    }

    public void setSize(Integer size) {
        this.container_size = size;
    }

    public Collection<CompanyPart> getCompanyParts() {
        return companyParts;
    }

    public void setCompanyParts(Collection<CompanyPart> companyParts) {
        this.companyParts = companyParts;
    }

    public Collection<Waste> getWaste() {
        return waste;
    }

    public void setWaste(Collection<Waste> waste) {
        this.waste = waste;
    }

    public Disposer getDisposer() {
        return disposer;
    }

    public void setDisposer(Disposer disposer) {
        this.disposer = disposer;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Container)) {
            return false;
        }
        Container other = (Container) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Container [id = " + id + "] [name = " + name + "]";
    }
}
